package org.springframework.listener;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.event.MyselfEvent;
import org.springframework.stereotype.Component;

/**
 * 自定义监听
 */
@Component
public class MyselfCommonListener implements ApplicationListener<ApplicationEvent> {

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        // 处理事件
		if (event instanceof MyselfEvent ){
			MyselfEvent event1 = (MyselfEvent) event;
			event1.event();
			System.out.println("监听接受事件");
			System.out.println("Received event with message: " + event1.getMessage());
		}

    }
}